//FileSystem.java
package composite.safe;

/**
 *@author:youtubezou
 *@version:2012-7-17
 */
public class FileSystem {
	private Folder root = new Folder("root", null);
	private Folder cur = root;
	private static String name = "Youtubezou";
	
	public boolean cd(String folderName){
		
		if ("..".equals(folderName)){
			Folder folder = cur.getParent();
			if(folder != null)
				cur = folder;
			return true;
		}
		
		if(".".equals(folderName))
			return true;
		
		Folder folder = cur.getFolder(folderName);
		if(folder != null) {
			cur = folder;
			return true;
		}
		
		return false;
	}
	
	public boolean md(String name){
		return cur.md(name);
	}
	
	public boolean rd(String name){
		return cur.rmdir(name);
	}
	
	public boolean edit(String name){
		return cur.edit(name);
	}
	
	public boolean del(String name){
		return cur.rmfile(name);
	}
	
	public void dir(){
		System.out.println(">>>>>>>>" + name + "<<<<<<<<<");
		System.out.println(cur);
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FileSystem fs = new FileSystem();
		
		fs.md("Unix");
		fs.md("Win");
		fs.edit("test.txt");
		fs.dir();
		fs.cd("Unix");
		fs.dir();
		fs.md("Label");
		fs.md("Botton");
		fs.cd("..");
		fs.dir();

	}

}
